package nc.ui.trade.bill;

import nc.vo.bd.access.BdinfoManager;
import nc.vo.bd.access.BdinfoVO;

public class UserDefItemFormularCreator {

	public String getCodeFieldEditFormular(String pk_bdinfo,
			String pkColumnName, String codeColumnName, String nameColumnName) {
		BdinfoVO bdinfovo = BdinfoManager.getBdInfoVO(pk_bdinfo);
		String tableName = bdinfovo.getTablename();
		String subjectField = bdinfovo.getCodefieldname();
		String pkFieldName = bdinfovo.getTablepkname();
		String nameField = bdinfovo.getNamefieldname();
		String result = "";
		if (bdinfovo.getBaseDocTableName() == null) {
			if (codeColumnName != null && codeColumnName.trim().length() > 0)
				result = codeColumnName + "->getColValue(" + tableName + ","
						+ subjectField + "," + pkFieldName + "," + pkColumnName
						+ "_ID)";
			if (nameColumnName != null && nameColumnName.trim().length() > 0) {
				if (result.length() > 0)
					result += ";";
				result += nameColumnName + "->getColValue(" + tableName + ","
						+ nameField + "," + pkFieldName + "," + pkColumnName
						+ "_ID)";
			}
		} else {
			String baseTableName = bdinfovo.getBaseDocTableName();
			String baseTablePKName = bdinfovo.getBaseDocTablePkName();
			if (codeColumnName != null && codeColumnName.trim().length() > 0)
				result = codeColumnName + "->getColValue(" + tableName + ","
						+ baseTablePKName + "," + pkFieldName + ","
						+ pkColumnName + "_ID);" + codeColumnName
						+ "->getColValue(" + baseTableName + "," + subjectField
						+ "," + baseTablePKName + "," + codeColumnName + ")";
			if (nameColumnName != null && nameColumnName.trim().length() > 0) {
				if (result.length() > 0)
					result += ";";
				result += nameColumnName + "->getColValue(" + tableName + ","
						+ baseTablePKName + "," + pkFieldName + ","
						+ pkColumnName + "_ID);" + nameColumnName
						+ "->getColValue(" + baseTableName + "," + nameField
						+ "," + baseTablePKName + "," + nameColumnName + ");";
			}
		}
		return result;
	}
}
